<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>获取方法的数组</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="reflectionclass.getmethod.html">« ReflectionClass::getMethod</a></li>
      <li style="float: right;"><a href="reflectionclass.getmodifiers.html">ReflectionClass::getModifiers »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.reflectionclass.html">ReflectionClass</a></li>
    <li>获取方法的数组</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="reflectionclass.getmethods" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">ReflectionClass::getMethods</h1>
  <p class="verinfo">(PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">ReflectionClass::getMethods</span> &mdash; <span class="dc-title">获取方法的数组</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-reflectionclass.getmethods-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>ReflectionClass::getMethods</strong></span>(<span class="methodparam"><span class="type">?</span><span class="type"><span class="type">int</span><span class="type"></span></span> <code class="parameter">$filter</code><span class="initializer"> = <strong><code>null</code></strong></span></span>): <span class="type">array</span></div>

  <p class="para rdfs-comment">
   获取类的方法的一个数组。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-reflectionclass.getmethods-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">filter</code></dt>

     <dd>

      <p class="para">
       过滤结果为仅包含某些属性的方法。默认不过滤。
      </p>
      <p class="para">
       
       <strong><code>ReflectionMethod::IS_STATIC</code></strong>、
       <strong><code>ReflectionMethod::IS_PUBLIC</code></strong>、
       <strong><code>ReflectionMethod::IS_PROTECTED</code></strong>、
       <strong><code>ReflectionMethod::IS_PRIVATE</code></strong>、
       <strong><code>ReflectionMethod::IS_ABSTRACT</code></strong>、
       <strong><code>ReflectionMethod::IS_FINAL</code></strong> 的按位或（OR），就会返回<em class="emphasis">任意</em>满足条件的属性。
      </p>
      <blockquote class="note"><p><strong class="note">注意</strong>: 
       <span class="simpara">
        请注意：其他位操作，例如 <code class="literal">~</code> 无法按预期运行。这个例子也就是说，无法获取所有的非静态方法。
       </span>
      </p></blockquote>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-reflectionclass.getmethods-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   包含每个方法 <span class="classname"><a href="class.reflectionmethod.html" class="classname">ReflectionMethod</a></span> 对象的<span class="type"><span class="type 数组">数组</span></span>。
  </p>
 </div>

 
 <div class="refsect1 changelog" id="refsect1-reflectionclass.getmethods-changelog">
  <h3 class="title">更新日志</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>版本</th>
      <th>说明</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>7.2.0</td>
      <td>
       <code class="parameter">filter</code> 现在允许为 null。
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-reflectionclass.getmethods-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-5163">
    <p><strong>示例 #1 <span class="methodname"><strong>ReflectionClass::getMethods()</strong></span> 的基本用法</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">class&nbsp;</span><span style="color: #0000BB">Apple&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;function&nbsp;</span><span style="color: #0000BB">firstMethod</span><span style="color: #007700">()&nbsp;{&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;final&nbsp;protected&nbsp;function&nbsp;</span><span style="color: #0000BB">secondMethod</span><span style="color: #007700">()&nbsp;{&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;static&nbsp;function&nbsp;</span><span style="color: #0000BB">thirdMethod</span><span style="color: #007700">()&nbsp;{&nbsp;}<br />}<br /><br /></span><span style="color: #0000BB">$class&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">ReflectionClass</span><span style="color: #007700">(</span><span style="color: #DD0000">'Apple'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$methods&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$class</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getMethods</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$methods</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
array(3) {
  [0]=&gt;
  object(ReflectionMethod)#2 (2) {
    [&quot;name&quot;]=&gt;
    string(11) &quot;firstMethod&quot;
    [&quot;class&quot;]=&gt;
    string(5) &quot;Apple&quot;
  }
  [1]=&gt;
  object(ReflectionMethod)#3 (2) {
    [&quot;name&quot;]=&gt;
    string(12) &quot;secondMethod&quot;
    [&quot;class&quot;]=&gt;
    string(5) &quot;Apple&quot;
  }
  [2]=&gt;
  object(ReflectionMethod)#4 (2) {
    [&quot;name&quot;]=&gt;
    string(11) &quot;thirdMethod&quot;
    [&quot;class&quot;]=&gt;
    string(5) &quot;Apple&quot;
  }
}
</pre></div>
    </div>
   </div>
  </p>
  <p class="para">
   <div class="example" id="example-5164">
    <p><strong>示例 #2 从 <span class="methodname"><strong>ReflectionClass::getMethods()</strong></span> 中过滤结果</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">class&nbsp;</span><span style="color: #0000BB">Apple&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;function&nbsp;</span><span style="color: #0000BB">firstMethod</span><span style="color: #007700">()&nbsp;{&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;final&nbsp;protected&nbsp;function&nbsp;</span><span style="color: #0000BB">secondMethod</span><span style="color: #007700">()&nbsp;{&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;static&nbsp;function&nbsp;</span><span style="color: #0000BB">thirdMethod</span><span style="color: #007700">()&nbsp;{&nbsp;}<br />}<br /><br /></span><span style="color: #0000BB">$class&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">ReflectionClass</span><span style="color: #007700">(</span><span style="color: #DD0000">'Apple'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$methods&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$class</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getMethods</span><span style="color: #007700">(</span><span style="color: #0000BB">ReflectionMethod</span><span style="color: #007700">::</span><span style="color: #0000BB">IS_STATIC&nbsp;</span><span style="color: #007700">|&nbsp;</span><span style="color: #0000BB">ReflectionMethod</span><span style="color: #007700">::</span><span style="color: #0000BB">IS_FINAL</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$methods</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
array(2) {
  [0]=&gt;
  object(ReflectionMethod)#2 (2) {
    [&quot;name&quot;]=&gt;
    string(12) &quot;secondMethod&quot;
    [&quot;class&quot;]=&gt;
    string(5) &quot;Apple&quot;
  }
  [1]=&gt;
  object(ReflectionMethod)#3 (2) {
    [&quot;name&quot;]=&gt;
    string(11) &quot;thirdMethod&quot;
    [&quot;class&quot;]=&gt;
    string(5) &quot;Apple&quot;
  }
}
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-reflectionclass.getmethods-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="methodname"><a href="reflectionclass.getmethod.html" class="methodname" rel="rdfs-seeAlso">ReflectionClass::getMethod()</a> - 获取类方法的 ReflectionMethod</span></li>
        <li class="member"><span class="function"><a href="function.get-class-methods.html" class="function" rel="rdfs-seeAlso">get_class_methods()</a> - 返回由类的方法名组成的数组</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>